package org.fing.edu.uy.admin.utils;

import org.fing.edu.uy.esbadp.core.AdpFlowCache;
import org.fing.edu.uy.esbadp.core.AdpFlowInterface;
import org.fing.edu.uy.esbadp.core.AdpFlowLIST;
import org.fing.edu.uy.esbadp.core.AdpFlowRBAL;
import org.fing.edu.uy.esbadp.core.AdpFlowRET;
import org.fing.edu.uy.esbadp.core.AdpFlowSYNC;
import org.fing.edu.uy.esbadp.core.AdpFlowTRN;
import org.fing.edu.uy.esbadp.core.AdpFlowUNI;
import org.primefaces.model.mindmap.DefaultMindmapNode;
import org.primefaces.model.mindmap.MindmapNode;

public class MindmapUtils {

	public static MindmapNode createMindmapNode(AdpFlowInterface data , boolean hoja) {
		String color  = "FFCC00" ;
		String nodeName = data.getServiceName();
		
		if(data instanceof AdpFlowLIST){			
			color  = "5399e0";		
			
		}else if (data instanceof AdpFlowUNI){		
			color  = "dd2566" ;	
			
		}else if (data instanceof AdpFlowSYNC){
			color  = "a3811d" ;	
			AdpFlowSYNC aux = (AdpFlowSYNC) data;
			nodeName = aux.getServiceName() + "-" +aux.getInvokeSyncName();
			
		}else if (data instanceof AdpFlowRBAL){
			color  = "85bf18" ;		
			
		}else if (data instanceof AdpFlowCache){
			AdpFlowCache aux = (AdpFlowCache) data;
			color  = "f7e118" ;	
			nodeName = aux.getServiceName() + "-" +aux.getCachedServiceName();
			
		}else if (data instanceof AdpFlowRET){
			AdpFlowRET aux = (AdpFlowRET) data;
			color  = "007f7f" ;	
			nodeName = aux.getServiceName() + "-" +aux.getDelay();			
			
		}else if (data instanceof AdpFlowTRN){
			AdpFlowTRN aux = (AdpFlowTRN) data;
			color  = "FFCC00" ;	
			nodeName = aux.getServiceName() + "-" +aux.getDesc();			
		}		
		
		DefaultMindmapNode ret = new DefaultMindmapNode(nodeName, nodeName, color, hoja);
		return ret;
	}
	
	public static MindmapNode createMindmapHistNode(AdpFlowInterface data , boolean hoja, boolean active, long index) {
		String color  = "c9c8c7" ;
		String nodeName = active ? String.valueOf(index) + "-" : "";
		
				
		if(data instanceof AdpFlowLIST){			
			color = !active ? "c9c8c7" : "5399e0";		
			nodeName += data.getServiceName();
			
		}else if (data instanceof AdpFlowUNI){		
			color = !active ? "c9c8c7" : "dd2566" ;	
			nodeName += data.getServiceName();
			
		}else if (data instanceof AdpFlowSYNC){
			color = !active ? "c9c8c7" :  "a3811d" ;	
			AdpFlowSYNC aux = (AdpFlowSYNC) data;
			nodeName += aux.getServiceName() + "-" +aux.getInvokeSyncName();
			
		}else if (data instanceof AdpFlowRBAL){
			color = !active ? "c9c8c7" : "85bf18" ;		
			nodeName += data.getServiceName();
			
		}else if (data instanceof AdpFlowCache){
			AdpFlowCache aux = (AdpFlowCache) data;
			color = !active ? "c9c8c7" : "f7e118" ;	
			nodeName += aux.getServiceName() + "-" +aux.getCachedServiceName();
			
		}else if (data instanceof AdpFlowRET){
			AdpFlowRET aux = (AdpFlowRET) data;
			color = !active ? "c9c8c7" : "007f7f" ;	
			nodeName += aux.getServiceName() + "-" +aux.getDelay();			
			
		}else if (data instanceof AdpFlowTRN){
			AdpFlowTRN aux = (AdpFlowTRN) data;
			color = !active ? "c9c8c7" :  "FFCC00" ;	
			nodeName += aux.getServiceName() + "-" +aux.getDesc();			
		}		
		
		DefaultMindmapNode ret = new DefaultMindmapNode(nodeName, nodeName, color, hoja);
		return ret;
	}
	
	
	
	
}
